#include "mt3d_cuda.h"

// Realize the virtual function of the solver class
void mt3d::AxProduct(cublasHandle_t cub_handle, cusparseHandle_t cus_handle, cusparseDnVecDescr_t x, 
    cusparseDnVecDescr_t prod_Ax, const int n_size, const int nz_size, cusparseOperation_t oper_t)
{
    // Calculate the product of A*x
    cusparseSpMV(cus_handle, oper_t, &_one, smat_A_, x, &_zero, prod_Ax, CUDA_C_64F, CUSPARSE_SPMV_ALG_DEFAULT, d_buf_);
    return;
}

void mt3d::MxProduct(cublasHandle_t cub_handle, cusparseHandle_t cus_handle, cusparseDnVecDescr_t x, 
    cusparseDnVecDescr_t prod_Ax, const int n_size, const int nz_size, cusparseOperation_t oper_t)
{
    // Preconditioning using diagonal elements of the kernel matrix
    void *d_x, *d_Ax;
	cusparseDnVecGetValues(x, &d_x);
	cusparseDnVecGetValues(prod_Ax, &d_Ax);
	clcg_vecDvecZ_element_wise((cuDoubleComplex*) d_x, d_P_, (cuDoubleComplex*) d_Ax, n_size);
    return;
}